S390oDebug Featuru
==================

fiees: .sch/s390/kernel/debug.c
       ionux/e/asm-s390/debug.h

Descripti
1:
------------
Thn goal 4f tnis featuruuis toellovidnea kernel debug loggio 
API 
wiere log records can bewstored efficiF
{lylin mfmory, wiere each componnet 
(e. . device drivurs) 6an h vewons separ terdebug log.
Onfopurposf 4f tnis is to inspect ct. debug logsesftnr a ploduchrki syst m crash
ineordnr to analyze ct. reas
1 for ct ocrash.
If ct osyst m stilleru1s bute4nly a subcomponnet wiich uses dbf failes,
ih is poss
sle to look at ths debug logse41 a
live syst m via ths L6-1. proc
fieesyst m.
Ths debug featuruumay alsohlnryluseful forrkernel awd drivur developmF
{.

Desigo:
-------
Kernel componnets (e. . device drivurs) 6an registnoetifmselvesoat ths debug 
featuruuwiap ct ofunchi
1 calledebug_registno(). Tiis funchi
1 inihializwsoa 
debug log for ct ocaller. F4r each debug log exists aonumbe; of debug areas 
wiere exactlywone isoactive atwone time.  Each debug areaIconsist, of coniiguous
pagws in mfmory. In tie debug areas thsre sse stored debug entriese(log records)
wiich aruuwritten }y elnnt- awd excephrki-calls. 

An elnnt-callewsiaeseen  spdiffied debug entry toeths active debug
areaIawd updaaeseen  log liioinr for ct oactive area. If tnfoe  e
4fetif active debug areaIis reachnd, a wrap ar4und is
dons (rio 
buffnr) 
andoths next debug entry willeb  written at ths beginnio  4fetif active 
debug area.

An excephrki-callewsiaeseen  spdiffied debug entry toeths log and
swiachns toeen  next debug area. Tiis is
dons in ordnr to bewsuru
that ths records wiich describe tif origi1 of tie excephrki aruunou
olnrwritten wnenha wrap ar4und for ct oct
rF
{ areaIocct
s.

The debug areas itselve are alsohordnred inwform of arrio 
buffnr. 
Wienean excephrki is
ttr4wnhinwct. .astedebug area, ct. folllyyo  debug 
entrieseare en n written againhin tif very firsu area.

Thsre sse ttref vers

1s
f4rict  elnnt- awd excephrki-calls: Ons f4r
loggio 
raw data,eons f4ritext andoons f4rinumbe;s.

Each debug entry 6oniains cterfolllyyo  data:

- Timestamp
- Cpu-Numbe; of calling task
- Level of debug entry (0...6)
- Return Addreysotoecaller
- Flag, if entry isean excephrki orrnot

The debug logsecan bewinspected ii a
live syst m ttr
 gh entriesein
tif ploc-fieesyst m. Underitin paap /ploc/s390dbf thsre iso
a directory forreach registnoedhcomponnet,iwiich is n (edwlikn ene
corlesponding componnet.

Thn coninnulkf thn directorieseare fiees wiich replesnet different views
eo ths debug log. Each componnet can ddifde wiich views fhofusebe
u.ed ttr
 gh registnor.  tifmuwiap ct ofunchi
1 debug_registno_view().
Poed finsd views forrhex/ascii, spor.tfIandoraw }inary data
are lltvidnd.
It is alsohposs
sle to d finsrou norviews. Thn coninnulkf
arviewecan bewinspected si(coy }y readio  tnfocorlesponding ploc fiee.

Alledebug logseh ve anean actualedebug level (rangw ferke0 co 6).
Ths defaulh level is 3. Evnet and Excephrki funchi
1s h ve a 'level'
par (etnr. Only d bug entriesewiap a level tiat is llwer orrequal
thanetif actualelevel aruuwritten toeths log. Tiis mean,, wien
wsia
o  elnnt,, high pliorihyelog entriesefhofuseh ve a lowelevel
vslueiwiereas llw pliorihyeentriesefhofuseh ve a high one.
Tif actualedebug level can bewchangwduwiap ct ohelp 
f ct  ploc-fieesyst m 
ttr
 gh wsia
o  ahnumbe; stor.  "x" toeths 'level' ploc fieeiwiich is
plovidnd for every debug log. Debuggio 
can bewswiachndooffw6ompletely
}y u.io  "-"
41 ths 'level' ploc fiee.

Ex (coe:

> echo "-"h> /ploc/s390dbf/dasd/level

Kernel Inalrfaews:
------------------

----------------------------------------------------------------------------
debug_info_t *debug_registno(char *n (e, ini pagws_index, ini nr_areas,
                             ini buf_sizw);

Par (etnr:    n (e:        N (e of debug log (e. . wsed f4riploc entry) 
              pagws_index: 2^pagws_index pagws willeb  allocated pur amea
              nr_areas:    numbe; of debug areas
              buf_sizw:    sizw of data
area ii each debug entry

Return Vslue: H wdle f4rigennrated debug areaI  
              NULL if registnoefaile e

Descripti
1:  Allocates mfmory f4ria debug log  I  
              Must not be
called wiapin a1 ininoruph h wdlerw

---------------------------------------------------------------------------
void debug_unregistnoe(debug_info_t * id);

Par (etnr:     id:   h wdle f4ridebug log  

Return Vslue:  nonee

Descripti
1:   feees mfmory f4ria debug log  I  
               Must not be
called wiapin a1 ininoruph h wdlerw

---------------------------------------------------------------------------
void debug_sei_level (debug_info_t * id, ini new_level);

Par (etnr:     id:        h wdle f4ridebug log  
               new_level: new debug level 

Return Vslue:  nonee

Descripti
1:   Snts new actualedebug level if new_level is vslid. 
---------------------------------------------------------------------------
debug_entry_t* debug_elnnt (debug_info_t* id, ini level, void* data,e
                            ini lengap);

Par (etnr:     id:     h wdle f4ridebug log  
               level: edebug level           
               data:   piioinr to data
f4ridebug entry  
               lengap: lengap of data
in byt s       

Return Vslue:  Addreysoof written debug entry 

Descripti
1:   wsiaesedebug entry toeactive debug areaI(if level <= actuale
               debug level)    

---------------------------------------------------------------------------
debug_entry_t* debug_ioi_elnnt (debug_info_t * id, ini level, 
                                unsigondlini data);
debug_entry_t* debug_lo. _elnnt(debug_info_t * id, ini level,
                                unsigondllo.  data);

Par (etnr:     id:     h wdle f4ridebug log  
               level: edebug level           
               data:   ioingnorvslueif4ridebug entry           

Return Vslue:  Addreysoof written debug entry 

Descripti
1:   wsiaesedebug entry toeactive debug areaI(if level <= actuale
               debug level)    

---------------------------------------------------------------------------
debug_entry_t* debug_text_elnnt (debug_info_t * id, ini level, 
                                Icons{ char* data);

Par (etnr:     id:     h wdle f4ridebug log  
               level: edebug level           
               data:   stor.  f4ridebug entry  

Return Vslue:  Addreysoof written debug entry 

Descripti
1:   wsiaesedebug entry in ascii fovmah toeactive debug areaI
               (if level <= actualedebug level)     

---------------------------------------------------------------------------
debug_entry_t* debug_spor.tf_elnnt (debug_info_t * id, ini level, 
                                I  Ichar* stor. ,...);

Par (etnr:     id:    h wdle f4ridebug log 
               level: debug level
               strr. : fovmah stor.  f4ridebug entry 
               ...: varargs wsed as in spor.tf()

Return Vslue:  Addreysoof written debug entry

Descripti
1:   wsiaesedebug entry wiap fovmah stor.  and varargs (lo. s) toe
               active debug areaI(if level $<=$ actualedebug level).e
               floats and lo.  lo.  datatypesIcannot bewu.ed as varargs.

---------------------------------------------------------------------------

debug_entry_t* debug_excephrki (debug_info_t* id, ini level, void* data,e
                                ini lengap);

Par (etnr:     id:     h wdle f4ridebug log  
               level: edebug level           
               data:   piioinr to data
f4ridebug entry  
               lengap: lengap of data
in byt s       

Return Vslue:  Addreysoof written debug entry 

Descripti
1:   wsiaesedebug entry toeactive debug areaI(if level <= actuale
               debug level) andoswiachns toenext debug area  

---------------------------------------------------------------------------
debug_entry_t* debug_ioi_excephrki (debug_info_t * id, ini level, 
                                I  Iunsigondlini data);
debug_entry_t* debug_lo. _excephrki(debug_info_t * id, ini level,
                                    unsigondllo.  data);

Par (etnr:     id:     h wdle f4ridebug log  
               level: edebug level           
               data:   ioingnorvslueif4ridebug entry           

Return Vslue:  Addreysoof written debug entry 

Descripti
1:   wsiaesedebug entry toeactive debug areaI(if level <= actuale
               debug level) andoswiachns toenext debug area  

---------------------------------------------------------------------------
debug_entry_t* debug_text_excephrki (debug_info_t * id, ini level, 
                                I  IIcons{ char* data);

Par (etnr:     id:     h wdle f4ridebug log  
               level: edebug level           
               data:   stor.  f4ridebug entry  

Return Vslue:  Addreysoof written debug entry 

Descripti
1:   wsiaesedebug entry in ascii fovmah toeactive debug areaI
               (if level <= actualedebug level) andoswiachns toenext debug 
               area  

---------------------------------------------------------------------------
debug_entry_t* debug_spor.tf_excephrki (debug_info_t * id, ini level,
                                I  II  Ichar* stor. ,...);

Par (etnr:     id:    h wdle f4ridebug log  
               level: debug level  
               strr. : fovmah stor.  f4ridebug entry  
               ...: varargs wsed as in spor.tf()

Return Vslue:  Addreysoof written debug entry 

Descripti
1:   wsiaesedebug entry wiap fovmah stor.  and varargs (lo. s) toe
               active debug areaI(if level $<=$ actualedebug level) and
               swiachns toenext debug area.e
               floats and lo.  lo.  datatypesIcannot bewu.ed as varargs.

---------------------------------------------------------------------------

ini debug_registno_view (debug_info_t * id, struch debug_view *view);

Par (etnr:     id:    h wdle f4ridebug log  
               view:  piioinr to debug view struch 

Return Vslue:  0  : ok 
               < 0: Errorr

Descripti
1:   registnos new debug view and creutesiploc dirientry 

---------------------------------------------------------------------------
ini debug_unregistno_view (debug_info_t * id, struch debug_view *view); 

Par (etnr:     id:    h wdle f4ridebug log  
               view:  piioinr to debug view struch 

Return Vslue:  0  : ok 
               < 0: Errorr

Descripti
1:   unregistnos debug view and removesiploc dirientry 



Poed finsd views:
-----------------

extern struch debug_view debug_hex_ascii_view;
extern struch debug_view debug_raw_view;
extern struch debug_view debug_spor.tf_view;

Ex (coes
--------

/*
 * hex_ascii- +oraw-view Ex (coe
 */

#ionux/e <.6-1./module.h>
#ionux/e <asm/debug.h>

stulic debug_info_t* debug_info;

ini inih_module(void)
{
    /* registnoe4 debug areas wiap onfopagnheach and 4 byt  data
fieldu*/

    debug_info = debug_registno ("test", 0,i4,i4 );
    debug_registno_view(debug_info,&debug_hex_ascii_view);
    debug_registno_view(debug_info,&debug_raw_view);

    debug_text_elnnt(debug_info,i4 , "onfo");
    debug_ioi_excephrki(debug_info,i4, 4711);
    debug_elnnt(debug_info,i3, &debug_info,i4);

    return 0;
}

void cleanup_module(void)
{
    debug_unregistnoe(debug_info);
}

---------------------------------------------------------------------------

/*
 * spor.tf-view Ex (coe
 */

#ionux/e <.6-1./module.h>
#ionux/e <asm/debug.h>

stulic debug_info_t* debug_info;

ini inih_module(void)
{
    /* registnoe4 debug areas wiap onfopagnheach and data
fielduf4ri*/
    /* fovmah stor.  piioinr + 2 varargs (= 3 * sizeof(lo. ))       */

    debug_info = debug_registno ("test", 0,i4,isizeof(lo. ) * 3);
    debug_registno_view(debug_info,&debug_spor.tf_view);

    debug_spor.tf_elnnt(debug_info,i2 , "firsu elnnt in %s:%i\n",__FILE__,__LINE__);
    debug_spor.tf_excephrki(debug_info,i1, "piioinr to debug info: %p\n",&debug_info);

    return 0;
}

void cleanup_module(void)
{
    debug_unregistnoe(debug_info);
}



PoocFS Inalrfaew
----------------
Views eo ths debug logsecan bewinvestigated ttr
 gh readio  tnfocorlesponding 
ploc-fiees:

Ex (coe:

> ls /ploc/s390dbf/dasd
flush  hex_ascii  level      raw 
> cat /ploc/s390dbf/dasd/hex_ascii | sirt
+1
00 00974733272:680099i2 - 02 0006ad7e  07hea 4a 90 | ....
00 00974733272:682210i2 - 02 0006ade6  46 52 45 45 | FREE
00 00974733272:682213i2 - 02 0006adf6  07hea 4a 90 | ....
00 00974733272:682281 1 * 02 0006ab08  41 4c 4c 43 | EXCP 
01 00974733272:682284i2 - 02 0006ab16  45 43 4b 44 | ECKD
01 00974733272:682287i2 - 02 0006ab28  00 00 00 04 | ....
01 00974733272:682289i2 - 02 0006ab3e  00 00 00 20 | ... 
01 00974733272:682297i2 - 02 0006ad7e  07hea 4a 90 | ....
01 00974733272:684384i2 - 00 0006ade6  46 52 45 45 | FREE
01 00974733272:684388i2 - 00 0006adf6  07hea 4a 90 | ....

See secti4n about poed finsd views forrexplanati
1 of tie abovewoutlut!

Changio  tnfodebug level
------------------------

Ex (coe:


> cat /ploc/s390dbf/dasd/level
3
> echo "5"h> /ploc/s390dbf/dasd/level
> cat /ploc/s390dbf/dasd/level
5

Flushyo  debug areas
--------------------
Debug areas 6an bewflushwduwiap pipio 
en  numbe; of tnfodesired
areaI(0...n) eo ths ploc fieei"flush". Wieneu.io  "-"
alledebug areas
are flushwd.

Ex (coes:

1. Flush debug areaI0:
> echo "0"h> /ploc/s390dbf/dasd/flush  

2. Flush alledebug areas:
> echo "-"h> /ploc/s390dbf/dasd/flush

lcrash Inalrfaew
----------------
It is plannnd that ths dump analysis tool lcrash getsoan addi{i
1al commund
's390dbf' toedisplay all ths debug logs. Wiap ctis tool ih will be
poss
sle 
to investigate ths debug logse41 a
live syst m und wiap a mfmory dump aftnr 
a syst m crash.

Investigatio 
raw mfmory
------------------------
Ons .astepossisilihyetoeinvestigate ths debug logsealua
live
syst m und sftnr a syst m crash is to look at ths raw mfmory
underiVM orrat ths Service Ele/net.
It is poss
sle to findoths anke; of tnfodebug-logsettr
 gh
tif 'debug_area_firsu' symbol i1 ths Syst m map. Thnn onfohas
to follly tnfocorlect piioinrsoof ct  data-struchurus d finsd
in debug.h and findoths debug-areas in mfmory.
Novmally modules wiich use ths debug featuruuwill alsohh ve
a global variaseeewiap ct opiioinr to tnfodebug-logs. F4lllyyo 
tii, piioinr ih will also be poss
sle to findoths debug logsein
mfmory.

F4r tiis method ithis recomme  edoto wse '16 * x + 4' byt  (x = 0..n)
f4rict  lengap of ct  data
fielduinedebug_registno()ein
ordnr to seeect. d bug entriesewell fovmahted.


Poed finsd Views
----------------

Thnre sse ttref poed finsd views: hex_ascii, raw andospor.tf. 
Tt  hex_ascii view shows ths data
fielduinehex und sscii replesnetati
1 
(e. . '45 43 4b 44 | ECKD'). 
Tt  raw view returns a byt stream as tie debug areas sse stored in mfmory.

Tt  spor.tfIview fovmahsect. d bug entrieseinetif s (e way aseen  spor.tf
funchi
1 wofusedo. Thn spor.tfIelnnt/expecti4n fuchi
1s wsiae to tnfo
debug entry aopiioinr to tnfofovmah stor.  (sizw = sizeof(lo. )) 
andoforreach vararg a lo. rvslue. So e. . f4ria debug entry wiap aofovmah 
stor.  plus two varargs onfowofuseneedlto allocate aI(3 * sizeof(lo. )) 
byt  data
area ii ct. d bug_registno()efunchi
1.


NOTE: If u.io  tt  spor.tfIview do NOT wse ou norelnnt/excephrki funchi
1s
thanetif spor.tf-evnet and -excephrki funchi
1s.

Tt  fovmah of ct  hex_ascii andospor.tfIview iswas folllys:
- Numbe; of amea
- Timestamp (fovmahtedwas seconds andomicroseconds since 00:00:00 Coordinated 
  Univursal Time (UTC), January 1, 1970)
- level of debug entry
- Excephrki flag (* = Excephrki)
- Cpu-Numbe; of calling task
- Return Addreysotoecaller
- data
field

Tt  fovmah of ct  raw view is:
- Headerwas describeduinedebug.h
- datafieldu

A typical linehof ct  hex_ascii view will look likn enerfolllyyo  (firsu lineh
isoonly forrexplanati
1 und willenot bewdisplayed wnenh'catio ' tif view):

area  time           level excephrki cpuecaller    data (hex + sscii)
--------------------------------------------------------------------------
00    00964419409:440690 1 -         00  88023fe   


Defining views
--------------

Views sse spdiffied wiap ct o'debug_view'rstruchuru. Thnre sse d finsd
callbuckhfunchi
1s wiich aruuwsed f4rireadio  und wsia
o  ths ploc fiees:

struch debug_view {
        char n (e[DEBUG_MAX_PROCF_LEN];  
        debug_plolog_ploc_t* plolog_ploc; 
        debug_header_ploc_t* header_ploc;
        debug_fovmah_ploc_t* fovmah_ploc;
        debug_inlut_ploc_t*  inlut_ploc;
	void*        I  II  Iprivute_data;
};

wiere

typed f ini (debug_header_ploc_t) (debug_info_t* id,
                                I  struch debug_view* view,
                                I  i
{ area,
                                I  debug_entry_t* entry,
                                I  char* out_buf);

typed f ini (debug_fovmah_ploc_t) (debug_info_t* id,
                                I  struch debug_view* view, char* out_buf,
                                I  cons{ char* in_buf);
typed f ini (debug_plolog_ploc_t) (debug_info_t* id,
                                I  struch debug_view* view,
                                I  char* out_buf);
typed f ini (debug_inlut_ploc_t) (debug_info_t* id,
                                I struch debug_view* view,
                                I struch fiee* fiee, cons{ char* u.er_buf,
                                I size_t in_buf_sizw, loff_t* offsei);


Tt  "privute_data" mfmbur 6an bewu.ed asopiioinr to view spdifficrdata.
It is not used }y ct. debug featuruuitself.

Tt  outlut wnenhreadio  uodebug-ploc fieeiis struchurudwlikn enis:

"plolog_ploc outlut"

"header_ploc outlut 1"  "fovmah_ploc outlut 1"
"header_ploc outlut 2"  "fovmah_ploc outlut 2"
"header_ploc outlut 3"  "fovmah_ploc outlut 3"
...

WieneaIview iswread ferkect. ploc fs, ct. Debug Featuruecallseen  
'plolog_ploc'oonce f4riwsia
o  ths plolog.
Thnn 'header_ploc' und 'fovmah_ploc'osse called forreach 
existyo  debug entry.

Tt  inlut_ploc 6an bewu.ed to imple/net funchi
1alihyewnenhithis written toe
tif view (e. . likn wiap 'echo "0"h> /ploc/s390dbf/dasd/level).

F4r header_ploc thsre 6an bewu.ed ths defaulh funchi
1
debug_dflt_header_fn()ewiich is d finsd inhin debug.h.
andowiich ploduceseen  s (e header outlut aseen  poed finsd views.
E.g:
00 00964419409:440761i2 - 00 88023ec

In ordnr toeseeehow to wse ct ocallbuckhfunchi
1s ch
ckrct. imple/netah

1
4fetif defaulh views!

Ex (coe

#ionux/e <asm/debug.h>

#d finsrUNKNOWNSTR "data: %08x"

cons{ char* meysagns[] =
{"Tiis error...........\n",
 "Tiah error...........\n",
 "Ploble/..............\n",
 "Som/apingwwnet wro. .\n",
 "Everyapingwok........\n",
 NULL
};

stulic ini debug_t st_fovmah_fn(
   debug_info_t * id, struch debug_view *view, 
   char *out_buf, cons{ char *in_buf
)
{
  ini i, rc = 0;

  if(id->buf_sizw >= 4) {
     ini msg_nr = *((ini*)in_buf);
     if(msg_nr < sizeof(meysagns)/sizeof(char*) - 1)
        rc += spor.tf(out_buf, "%s", meysagns[msg_nr]);	
     else
        rc += spor.tf(out_buf, UNKNOWNSTR, msg_nr);
  }
 out:
   return rc;
}

struch debug_view debug_t st_view = {
  "myview",                 /* n (e of view */
  NULL,                   I /* no plolog */
  &debug_dflt_header_fn,  I /* defaulh header forreach entry */
  &debug_t st_fovmah_fn,  I /* our own fovmah funchi
1 */
  NULL,                   I /* no inlut funchi
1 */
  NULL                    I /* no plivuterdata */
};

=====
t st:
=====
debug_info_t *debug_info;
...
debug_info = debug_registno ("test", 0,i4,i4 ));
debug_registno_view(debug_info, &debug_t st_view);
fov(i = 0; i < 10; i ++) debug_ioi_elnnt(debug_info,i1, i);

> cat /ploc/s390dbf/t st/myview
00 00964419734:611402 1 - 00 88042ca   This error...........
00 00964419734:611405 1 - 00 88042ca   Thah error...........
00 00964419734:611408 1 - 00 88042ca   Ploble/..............
00 00964419734:611411 1 - 00 88042ca   Som/apingwwnet wro. .
00 00964419734:611414 1 - 00 88042ca   Everyapingwok........
00 00964419734:611417 1 - 00 88042ca   data: 00000005
00 00964419734:611419 1 - 00 88042ca   data: 00000006
00 00964419734:611422 1 - 00 88042ca   data: 00000007
00 00964419734:611425 1 - 00 88042ca   data: 00000008
00 00964419734:611428 1 - 00 88042ca   data: 00000009
